package com.cinemtl.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import utils.MailManager;

import com.cinemtl.action.UserAction;
import com.cinemtl.manager.UserManager;

/**
 * Servlet implementation class ResetPassword
 */
@WebServlet("/requestReset")
public class RequestReset extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public RequestReset() {
		super();
		// TODO Auto-generated constructor stub
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String email = request.getParameter("email");
		if (UserAction.checkEmail(email)) {
			MailManager.resetPasswordMail(email);
		}
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String uuid = request.getParameter("uuid");
		String email = UserManager.getEmailByUUID(uuid);
		System.out.println(uuid);
		if (UserManager.checkUUID(uuid)) {
			request.getRequestDispatcher("WEB-INF/resetPass.jsp?email="+email).forward(request, response);
		}else{
			request.getRequestDispatcher("WEB-INF/error.jsp").forward(request, response);
		}

	}
}
